//
//  Person.m
//  NSArray详解
//
//  Created by 大欢 on 16/5/24.
//  Copyright © 2016年 大欢. All rights reserved.
//

#import "Person.h"

@implementation Person

- (void)run {
    
    NSLog(@"running man %@",self);
}

- (BOOL)isEqual:(id)object {
    
    if (self == object) {
        return YES;
    }
    
    if ([self class] != [object class]) {
        return NO;
    }
    
    Person * p = (Person *)object;
    
    if (![self.name isEqualToString:p.name]) {
        return NO;
    }
    
    if (self.age != p.age) {
        return NO;
    }
    
    return YES;
}

//- (NSUInteger)hash {
//    
//    return _age^_name
//}


- (NSComparisonResult)compareAge:(Person *)person {
    
    if (self.age < person.age) {
        return NSOrderedDescending;
    } else if (self.age > person.age) {
        return NSOrderedAscending;
    }
    return NSOrderedSame;
}

- (NSString *)description {
    
    return [NSString stringWithFormat:@"name = %@ age = %ld",_name,_age];
}

@end
